#include "reminditem.h"
#include "ui_reminditem.h"
#include "remindedit.h"
#include "QDate"
RemindItem::RemindItem(QWidget *parent,long id,QString name,QString imgURL,long amount,QDate time) :
    QWidget(parent),
    ui(new Ui::RemindItem)
{
    ui->setupUi(this);

}

void RemindItem::update(Remind remind){
    this->remind = remind;
    ui->label_name->setText(this->remind.name);
    ui->lable_image->showURLImage(this->remind.pic);
    ui->label_amount->setText("数量："+QString::number(this->remind.amount));
    ui->label_time->setText("过期时间："+this->remind.date.toString("yyyy 年 MM 月 dd 日"));
    connect(ui->btn_edit,&QPushButton::clicked,this,[=](){
//        qDebug()<<"想要修改"<<id<<"的存储";
        RemindEdit* re = new RemindEdit(this);
        re->update(remind);
        connect(re,&RemindEdit::confirm,this,[=](long newAmount,QDate date){
            ui->label_amount->setText("数量："+QString::number(newAmount));
            ui->label_time->setText("过期时间："+date.toString("yyyy 年 MM 月 dd 日"));
            sql->remindUpdate(this->remind.id,newAmount,date);
            // TODO sql 更新数据库
        });
        re->show();
    });
    connect(ui->btn_delete,&QPushButton::clicked,this,[=](){
        emit deleteSignal();
        sql->remindDelete(this->remind.id);
    });
}
RemindItem::~RemindItem()
{
    delete ui;
}
